{% extends "BillingBundle::admin_layout.html.twig" %}

{% macro field(row, lname, label) %}
    <tr>
        <td class="label">
            <label id="l{{ lname }}" for="{{ lname }}">{{ label }}:</label>
        </td>
        <td class="field">
            {{ form_widget(row) }}
        </td>
        <td class="status"></td>
        <td>
            {{ form_errors(row) }}
        </td>
    </tr>
{% endmacro %}

{% block content %}

<link rel="stylesheet" type="text/css" media="screen" href="{{ asset('bundles/billing/css/validate.css') }}" />
<script src="{{ asset('bundles/billing/js/jquery.js') }}" type="text/javascript"></script>
<script src="{{ asset('bundles/billing/js/jquery.validate.js') }}" type="text/javascript"></script>
<script src="{{ asset('bundles/billing/js/validate_tarifs_terms.js') }}" type="text/javascript"></script>

<body onLoad="javascript:addOptions()">
<h4>Создание нового тарифа-срока:</h4>

<div id="add_box">
  <div id="add_wrap">
    <form id="add_form" method="post" action="#">
        <table>
           {{ _self.field(form.term, 'term', 'Срок') }}
           {{ _self.field(form.tarif_id, 'tarif_id', 'Тариф') }}

           <tr>
               <td class="label">
                    <label id="ltarif_type_id" for="tarif_type_id">Тип тарифа:</label>
               </td>
               <td class="field">
                   {{ form_widget(form.tarif_type_id, { 'attr': {'onChange': 'addOptions()'} }) }}
               </td>
               <td class="status"></td>
               <td>
                   {{ form_errors(form.tarif_type_id) }}
               </td>
           </tr>
           {{ form_widget(form._token) }}
        <tr>
            <td>
            <div class="field">
                <input name="add_tarif_term" type="submit" value="Создать"/>
            </div>
            </td>
        </tr>
        </table>
    </form>
   </div>
</div>
</body>

<script type="text/javascript">
function addOptions()
{
    var objSel = document.getElementById("orderstarifsterms_tarif_type_id");
    var tarifs = document.getElementById("orderstarifsterms_tarif_id");
    tarifs.options.length = 0;
    if ( objSel.selectedIndex == 0)
    {
        {% for sharedTarif in sharedTarifs %}
            tarifs.options[tarifs.options.length] = new Option("{{ sharedTarif.getName() }}", "{{ sharedTarif.getId() }}");
        {% endfor %}   
    }
    if ( objSel.selectedIndex == 1)
    {
        {% for vpsTarif in vpsTarifs %}
            tarifs.options[tarifs.options.length] = new Option("{{ vpsTarif.getName() }}", "{{ vpsTarif.getId() }}");
        {% endfor %} 
    }
}
</script>

{% endblock %}
